package com.project_test.kun.travelling_1st.HomePage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

//import com.example.administrator.thefirsttravel.R;
//import com.example.administrator.thefirsttravel.category.HomePListItemButton;
import com.project_test.kun.travelling_1st.HomePage.category.HomePListItemButton;
import com.project_test.kun.travelling_1st.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 16-10-19.
 */
public class HomePHeadGridAdapter extends BaseAdapter {
    private Context mContext;
    private List<HomePListItemButton> data;
    private ViewHolder mHolder;

    public HomePHeadGridAdapter(Context context, List<HomePListItemButton> data) {
        mContext = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data!=null?data.size():0;
    }

    @Override
    public HomePListItemButton getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view==null){
            view= LayoutInflater.from(mContext).inflate(R.layout.item_grid_head_fragment_home,viewGroup,false);
            mHolder = new ViewHolder();
            mHolder.icon= (ImageView) view.findViewById(R.id.icon_grid_head_fragment_home);
            mHolder.name= (TextView) view.findViewById(R.id.name_grid_head_fragment_home);
            view.setTag(mHolder);
        }else{
            mHolder= (ViewHolder) view.getTag();
        }
        //赋值
        HomePListItemButton button = data.get(i);
        mHolder.name.setText(button.getName());
        Picasso.with(mContext).load(button.getIcon()).into(mHolder.icon);
        return view;
    }

    static class ViewHolder{
        public ImageView icon;
        public TextView name;

    }
}
